package com.uzai.console.web.locallive;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.locallive.elmtoken.ElmTokenIdDto;
import com.uzai.console.dto.locallive.elmtoken.ElmTokenQuery;
import com.uzai.console.dto.locallive.elmtoken.ElmTokenUpdatePidDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.locallive.ElmTokenService;
import com.uzai.console.vo.locallive.elmtoken.ElmTokenAuthUrlVo;
import com.uzai.console.vo.locallive.elmtoken.ElmTokenInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 饿了么
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "饿了么联盟",tags = "本地生活|授权管理|饿了么联盟")
@ApiSort(13)
@RestController
public class ElmTokenController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(ElmTokenController.class);

    @Autowired
    private ElmTokenService elmTokenService;

    @ApiOperation(value = "分页查询饿了么联盟列表", notes = "分页查询饿了么联盟列表", response = ElmTokenInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/elmToken/findElmTokenList")
    public Object findElmTokenList(@RequestBody ElmTokenQuery elmTokenQuery){
        return elmTokenService.findElmTokenList(elmTokenQuery);
    }

    @SystemLogType(model = SystemModelEnum.ElmToken, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加联盟账号", notes = "添加联盟账号", response = ElmTokenAuthUrlVo.class)
    @ApiOperationSupport(order = 4)
    @PostMapping("/elmToken/addToken")
    public Object addToken(){
        return elmTokenService.addElmToken(getLoginInfo().getMerId());
    }

    @SystemLogType(model = SystemModelEnum.ElmToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "重新授权", notes = "重新授权", response = ElmTokenAuthUrlVo.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/elmToken/reauthorize")
    public Object reauthorize(){
        return elmTokenService.addElmToken(getLoginInfo().getMerId());
    }

    @ApiOperation(value = "查询联盟详情", notes = "查询联盟详情", response = ElmTokenInfoVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/elmToken/findElmTokenInfo")
    public Object findElmTokenInfo(@RequestBody ElmTokenIdDto elmTokenIdDto){
        return elmTokenService.findElmTokenInfo(elmTokenIdDto);
    }

    @SystemLogType(model = SystemModelEnum.ElmToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "设置推广位", notes = "设置推广位")
    @ApiOperationSupport(order = 7)
    @PostMapping("/elmToken/updatePid")
    public Object updatePid(@RequestBody ElmTokenUpdatePidDto elmTokenUpdatePidDto){
        elmTokenService.updatePid(elmTokenUpdatePidDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.ElmToken, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除", notes = "删除")
    @ApiOperationSupport(order = 9)
    @PostMapping("/elmToken/deleteElmToken")
    public Object deleteElmToken(@RequestBody ElmTokenIdDto elmTokenIdDto){
        elmTokenService.deleteElmToken(elmTokenIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.ElmToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "授权共享渠道id", notes = "授权共享渠道id")
    @ApiOperationSupport(order = 10)
    @PostMapping("/elmToken/authRelationId")
    public Object authRelationId(){
        return elmTokenService.authRelationId(getLoginInfo().getMerId());
    }

    @SystemLogType(model = SystemModelEnum.ElmToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "清空全部渠道id", notes = "清空全部渠道id")
    @ApiOperationSupport(order = 11)
    @PostMapping("/elmToken/cleanRelationId")
    public Object cleanRelationId(@RequestBody ElmTokenIdDto elmTokenIdDto){
        elmTokenService.cleanRelationId(elmTokenIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.ElmToken, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "刷新全部渠道id", notes = "刷新全部渠道id")
    @ApiOperationSupport(order = 11)
    @PostMapping("/elmToken/reflashRelationId")
    public Object reflashRelationId(@RequestBody ElmTokenIdDto elmTokenIdDto){
        elmTokenService.reflashRelationId(elmTokenIdDto);
        return true;
    }


}
